<?php
/*DEE_DESC
 $templ=array(
	//Название шаблона в списке ОБЯЗАТЕЛЬНОЕ
	'title'=>'Поиск',
	);
//DEE_DESC_END*/


	$view->meta_robots = 'noindex,follow';

	$pr_html = $html = '';	
	$limit = 18;

	$users = isset( $GLOBALS['users'] ) ? $GLOBALS['users'] : array();
	$admin = in_array( $user->id, $users ) ? true : false;
	
	$search_text = isset( $_GET['q'] ) ? trim( $_GET['q'] ) : '';
	if( strlen( $search_text ) > 2 )
	{
		$params = array(
			'where'	=> '( `index_full_name` LIKE "%'.getGoodUrl( $search_text, '' ).'%" OR `product_code` LIKE "%'.$search_text.'%" ) AND pp IN(1,3,4,5,0)',
            'order'	=> 'find_in_set( pp, "1,3,4,5,0" )',
			'limit'	=> $limit,
			'limit_num'	=> $view->paginator_index * $limit,
		);
		$products = getProductList( $params );
			
		if( $products['count'] )
		{
			foreach( $products['list'] as $product )
				$pr_html .= $load->block( 'product', array( 'product' => $product ) );
			
			$html = $this->view->printH1('s').'
						<div class="initial-info">
							<span>По запросу <b>'.$search_text.'</b> найдено '.$products['count'].' товаров</span>
						</div>
						<div class="goods-list">
							<ul class="goods-list__inner">'
								.$pr_html.'
							</ul>
						</div>
						'.$load->block(
								'pagination',array( 
								'total'			=> $products['count'] ,
								'limit'			=> $limit , 
								'url_before'	=> $view->url_before.'/'.$view->url , 
								'url_after'		=> '?q='.$search_text
						));
		}
	}
	$view->gText .= $html ? $html : '<span>По запросу <b>'.$search_text.'</b> ничего не найдено';
